<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:z-index="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link rel="shortcut icon" th:href="@{/static/image/logo/favicon.ico}" type="image/x-icon"/>
    <link th:replace="common/base::static"/>
    <style>

        /*body {
            background-image:url(/static/css/background/1.jpg);
        }*/

        /*body {
            background: url(/static/images/background/66.jpg) no-repeat 0 0;
            background-size: 100% 200%;
        }*/

        .title {
            font-size: 40px;
            -webkit-text-stroke: 1px #fbfbfb;
            -webkit-text-fill-color: transparent;
        }
        .title2 {
            font-size: 40px;
            background: linear-gradient(to bottom,white,black);
            -webkit-text-fill-color: transparent;
            -webkit-background-clip: text;
        }

        ::-webkit-scrollbar {
            overflow-x: hidden;
        }
    </style>
</head>
<body style="background-color: #8CA7F8;">
<div class="kvf-user-login" id="kUserLoginBox" style="z-index: 2; position: absolute; padding-left: 43%">

    <div class="kvf-user-login-main" style="background-color: #1380d2">
        <div class="kvf-user-login-box kvf-user-login-header">
            <h2 class="title"><b>后台管理系统</b></h2>
        </div>
        <div class="layui-form kvf-user-login-box">
            <div class="layui-form-item">
                <label class="kvf-user-login-icon layui-icon layui-icon-username" for="kUserLoginUsername"></label>
                <input type="text" name="username" id="kUserLoginUsername" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="kvf-user-login-icon layui-icon layui-icon-password" for="kUserLoginPassword"></label>
                <input type="password" name="password" id="kUserLoginPassword" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="kvf-user-login-icon layui-icon layui-icon-vercode" for="kUserLoginVercode"></label>
                        <input type="text" name="vercode" id="kUserLoginVercode"  placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img th:src="@{/captcha}" class="kvf-user-login-codeimg" id="kUserGetVerCode" title="点击刷新验证码">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="rememberMe" lay-skin="primary" title="记住密码">
                <a href="forget.html" class="kvf-user-jump-change" style="margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button id="submitBtn" class="layui-btn layui-btn-fluid" lay-submit lay-filter="kUserLoginSubmit">登 录</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号登入</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="reg.html" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
            </div>
        </div>
    </div>

    <div class="layui-trans kvf-user-login-footer" id="footer" style="padding-left: 70%">
        <p>© 2020 <a href="https://tools.kalvinbg.cn" target="_blank">kvf.com</a></p>
    </div>
</div>

<div id="fader" style="z-index: 1; position: absolute">
    <ul>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/11.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/22.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/33.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/44.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/55.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/66.jpg"/></div>
        </li>
        <li style="background:#0f43ba;">
            <div><img src="static/images/background/77.jpg"/></div>
        </li>
    </ul>
</div>


<!--平滑切换背景图-->
<script type="text/javascript" src="static/js/fader.js"></script>
<link rel="stylesheet" type="text/css" href="static/css/fader.css">
<script type="text/javascript">
    var fader = new Hongru.fader.init('fader', {
        id: 'fader'
    });
</script>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script>

    //禁止滚动条滚动
    function unScroll() {
        var top = $(document).scrollTop();
        $(document).on('scroll.unable',function (e) {
            $(document).scrollTop(top);
        })
    }

    //移除禁止滚动条滚动
    function removeUnScroll() {
        $(document).unbind("scroll.unable");
    }

    layui.use('form', function () {
        var form = layui.form;

        $('body').css('overflow','hidden');
        unScroll();

        // 监听窗口尺寸变化
        // window.onload = function() {
        //     var oMain = document.querySelector('#kUserLoginBox');
        //     (function(doc, win) {
        //         var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        //             recalc = function() {
        //                 console.log('窗口大小被改变啦。。。');
        //                 oMain.style.left = (document.documentElement.clientWidth - oMain.offsetWidth) / 2 + 'px';
        //                 oMain.style.top = (document.documentElement.clientHeight - oMain.offsetHeight) / 2 + 'px';
        //             };
        //         if(!doc.addEventListener) {
        //             return false;
        //         }
        //         win.addEventListener(resizeEvt, recalc, false);
        //         doc.addEventListener('DOMContentLoaded', recalc, false);
        //     })(document, window);
        // };

        // 随机展示背景图片(这种方式太突兀)
        // var imgSrcs = [
        //     "static/images/background/1.jpg",
        //     "static/images/background/2.jpg",
        //     "static/images/background/3.jpg",
        //     "static/images/background/4.jpg",
        //     "static/images/background/66.jpg",
        //     "static/images/background/77.jpg"];
        //
        // setInterval(function(){
        //     $(document).ready(
        //         function() {
        //             console.log('触发成功');
        //             var randomBgIndex = parseInt(Math.random() * (imgSrcs.length));
        //             console.log('换背景图方法触发');
        //             $("body").css("background-image","url(" + imgSrcs[randomBgIndex] + ")");
        //             $("body").css("background-size", "100% 200%");
        //         }
        //     );
        // }, 3000);

        //提交
        form.on('submit(kUserLoginSubmit)', function(obj) {
            //请求登入接口
            kvfKit.aPost(api.login, obj.field, function (r) {
                if (r.code === req.status.ok) {
                    // todo 请求成功后，写入 access_token
                    /*layui.data(setter.tableName, {
                        key: setter.request.tokenName
                        ,value: res.data.access_token
                    });*/
                    // 登入成功的提示与跳转
                    layer.msg('登录成功', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 500
                    }, function() {
                        // 解决session过期在iframe页面登录后，主页嵌套在iframe里面的问题
                        if (window !== top) {
                            top.location.href = api.homeView;
                        } else {
                            location.href = api.homeView; // kvf-admin首页
                        }
                    });

                } else {
                    if (r.msg.indexOf('验证码') !== -1) {
                        kvfKit.unhappyMsg(r.msg + '，请重试。', true);
                        refreshVerCode();
                    } else {
                        kvfKit.unhappyMsg(r.msg, true);
                        refreshVerCode();
                    }
                }
            });
        });

        // 绑定监听回车事件
        kvfKit.bindEnterEventForLayuiForm();


        $('#kUserGetVerCode').on('click', function () {
            refreshVerCode();
        });

        // 刷新图片验证码
        function refreshVerCode() {
            $('#kUserGetVerCode').attr('src', api.captchaUrl + '?t=' + Math.random());
            $('#kUserLoginVercode').val('');
        }

    })
</script>
</body>
</html>